<template>
  <div id="app">
    <!-- 顶部通栏 -->
    <TopBar :key="topBarKey"></TopBar>
    <!-- 头部 -->
    <Header></Header>
    <!-- 中间变换部分 -->
    <router-view @changeTopBarKey="topBarKey++" />
    <!-- 尾部 -->
    <Footer></Footer>
    <Login v-show="isShowModal"></Login>
    <Transition name="slide">
      <Toast v-show="isShowToast"></Toast>
    </Transition>
  </div>
</template>
<script>
import TopBar from "@/components/TopBar.vue";
import Header from "@/components/Header.vue";
import Footer from "@/components/Footer.vue";
import Login from "@/components/Login.vue";
import Toast from "@/components/Toast.vue";

// import axios from "@/request/request";
import { JingpinAPI } from "@/request/Api";
import { mapState, mapMutations } from "vuex";

export default {
  data() {
    return { topBarKey: 0 };
  },
  components: { TopBar, Header, Footer, Login, Toast },
  computed: {
    ...mapState({
      isShowModal: (state) => state.showModal.isShowModal,
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  methods: {
    ...mapMutations({
      changeIsLogined: "loginStatus/changeIsLogined",
    }),
  },
  // axios发送请求
  async created() {
    // JingpinAPI().then(
    //   (res) => {
    //     console.log("res" + res);
    //   },
    //   (err) => {
    //     console.log("err" + err);
    //   }
    // );
    // let res = await JingpinAPI();
    // console.log(res);
    // console.log(process.env.VUE_APP_TXT);
  },
  watch: {
    "$route.path": {
      handler() {
        // this.changeIsLogined(true);
        this.topBarKey++;
      },
    },
  },
};
</script>
<style lang="less">
#app {
}
/* 入场的起始状态 = 离场的结束状态 */
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.3s linear;
}

.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
